Skip to content

feat: add ext2 write support - #33

Merged
kwrx merged 1 commit into
mainfrom
feat/ext2_write
Jun 14, 2026
Merged

feat: add ext2 write support#33
kwrx merged 1 commit into
mainfrom
feat/ext2_write

Conversation

@kwrx

@kwrx kwrx commented Jun 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

@kwrx
kwrx requested a review from Copilot June 14, 2026 02:22
@kwrx kwrx self-assigned this Jun 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements write-path functionality for the ext2 filesystem, including inode/block allocation, directory entry mutation, truncate/unlink support, and syscall-level O_TRUNC handling to enable basic POSIX file updates.

Changes:

  • Add ext2 write support (block/inode allocation, file writes, truncate, create, unlink) and wire new ops into mount/inode creation.
  • Refactor ext2 low-level utilities (block/group desc I/O, inode sizing helpers, directory entry helpers) to support the write path.
  • Add a userspace ext2 write/truncate/unlink regression test.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libk/utils/cache.c Fix cache commit to pass the correct cached value to commit handler.
kernel/syscalls/257_openat.c Add O_TRUNC handling via vfs_truncate() for regular files opened for write.
kernel/fs/ext2/utils/ext2_inode.c Implement inode allocation/free and block-mapping based inode data read/write/free.
kernel/fs/ext2/utils/ext2_dir.c Add helpers to add/remove directory entries and map dirent types.
kernel/fs/ext2/utils/ext2_block.c Add block alloc/free, superblock/group-desc read/write, and harden block I/O with validation + error returns.
kernel/fs/ext2/ext2.h Add layout asserts, inode size helpers, and expose new ext2 utility APIs + ops.
kernel/fs/ext2/ext2_write.c Rewrite ext2 write logic to allocate blocks on demand and support holes.
kernel/fs/ext2/ext2_unlink.c Add ext2 unlink implementation for regular files.
kernel/fs/ext2/ext2_umount.c Ensure ext2 block cache is destroyed on unmount.
kernel/fs/ext2/ext2_truncate.c Add ext2 truncate implementation (grow with zero-fill, shrink freeing blocks).
kernel/fs/ext2/ext2_setattr.c Enforce read-only mounts and commit inode metadata updates via ext2 icache commit.
kernel/fs/ext2/ext2_readlink.c Update to new inode-data API and add ext2 lock around on-disk readlink path.
kernel/fs/ext2/ext2_readdir.c Rewrite readdir to robustly parse entries and emit multiple results per call.
kernel/fs/ext2/ext2_read.c Rewrite read path to new inode-data API with locking and bounds checks.
kernel/fs/ext2/ext2_mount.c Add feature validation, compute group counts safely, and wire in setattr/creat/unlink ops and caches.
kernel/fs/ext2/ext2_getattr.c Fix time fields and use unified inode size getter; set blksize from statvfs.
kernel/fs/ext2/ext2_fsync.c Flush inode cache and forward fsync to underlying device inode.
kernel/fs/ext2/ext2_finddir.c Add shared inode creation helper and harden directory parsing/search logic.
kernel/fs/ext2/ext2_creat.c Add ext2 create implementation for regular files (alloc inode + add dir entry).
kernel/fs/ext2/ext2_cache.c Make inode cache allocate ext2 inode-sized entries and persist on commit when writable.
drivers/dev/block/main.c Invalidate per-device block cache at start of write path.
apps/test/ext2-write-test/Makefile Add build rules for a new ext2 write regression test app.
apps/test/ext2-write-test/main.c Add userspace test covering write patterns, holes, truncate grow/shrink, O_TRUNC, and unlink.
.gitignore Ignore AGENTS.md and normalize .pdb ignore line formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +52 to 54
if (unlikely(pos < 0 || (uint64_t)pos > UINT64_MAX - len))
return errno = EINVAL, -1;

}
}

ext2_inode_set_size(ext2, node, new_size);
Comment on lines +108 to +109
if (!result)
errno = errno == EIO ? EIO : ENOENT;
@kwrx
kwrx merged commit fa61899 into main Jun 14, 2026
1 check passed
@kwrx
kwrx deleted the feat/ext2_write branch June 14, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants